package com.fourcitizens.playas

import net.sf.json.* 
import grails.converters.JSON

class BeachRestController {

    def townService
	def provinceService
	def beachService

	def list = { 
			def country = Country.findByName(params.countryName)
			def province = provinceService.getProvinceInCountry(country, params.provinceName)
			def town = townService.getTownInProvince(province, params.townName)
			def beaches = town.beaches
			def jsonBeaches = []
			
			beaches.each { beach ->
				jsonBeaches.add(beachService.convertToJSONBeach(beach))
			}
			
			//render JSONSerializer.toJSON(jsonBeaches)
			//render beaches as JSON
			render jsonBeaches as grails.converters.JSON
	}
	def show = { 
			def country = Country.findByName(params.countryName)
			def province = provinceService.getProvinceInCountry(country, params.provinceName)
			def town = townService.getTownInProvince(province, params.townName)
			def beach = beachService.getBeachInTown(town,params.beachName)
			
			render beachService.convertToJSONObject(beach) as JSON
	}

}


